package cn.lan.code.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger注册
 * @author lanping
 * @version 1.0
 * @date 2021-11-02
 */
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class Swagger2Config {

    private ApiInfo apiInfo(String sysName) {

        ApiInfo apiInfo = new ApiInfoBuilder()
                .title(sysName+"服务")
                .description(sysName+"服务接口文档")
                .termsOfServiceUrl("http://127.0.0.1:8080/")
                .contact(new Contact("lanping", "http://127.0.0.1:8080/doc.html","1160669252@qq.com"))
                .version("v1.0.0").build();

        return apiInfo;
    }

    @Bean
    public Docket createAPI() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo("Springboot Code generator服务"))
                .pathMapping("/")
                .groupName("Springboot Code generator服务API文档")
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.lan.code.controller"))
                .paths(PathSelectors.any())
                .build();
    }

}
